package com.kkb.controller;

import com.github.pagehelper.PageInfo;
import com.kkb.pojo.Doctor;
import com.kkb.pojo.Hosregister;
import com.kkb.service.DoctorService;
import com.kkb.service.HosregisterService;
import com.kkb.utils.RandomUtil;
import com.kkb.utils.ResultUtil;
import com.kkb.vo.HosRegisterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * @author:CoolTiger
 * @title: HosregisterController
 * @projectName hospital1.0
 * @description: TODO
 * @date:2022/07/18/20:08:44
 **/
@Controller
@ResponseBody
@RequestMapping("/hospital/hosRegister")
public class HosregisterController {
    @Autowired
    private HosregisterService hosregisterService;
    /**
     * TODO 多条件查询所有挂号信息
     *
     * @param pageNum
     * @param pageSize
     * @param vo
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResultUtil<Hosregister> findAll(Integer pageNum, Integer pageSize, HosRegisterVO vo) {
        System.out.println(vo);
        if (pageNum == null || pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null || pageSize <= 0) {
            pageSize = 5;
        }
        PageInfo<Hosregister> hosregisterPageInfo = hosregisterService.queryAll(pageNum, pageSize, vo);
        return new ResultUtil<Hosregister>(hosregisterPageInfo);
    }

    /**
     * TODO 添加挂号信息
     *
     * @param hosregister
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.POST)
    public ResultUtil<Hosregister> addHosRegister(Hosregister hosregister) {

        int i = hosregisterService.addHosRegister(hosregister);
        if (i == 1) {
            return new ResultUtil<>(200,"挂号成功");
        }
        return new ResultUtil<>(500, "挂号失败");
    }

    /**
     * 退号
     *
     * @param hosRegisterId
     * @return
     */
    @RequestMapping(value = "{id}", method = RequestMethod.DELETE)
    public ResultUtil<Hosregister> deleteHosRegister(@PathVariable("id") Integer hosRegisterId) {
        int i = hosregisterService.eixtHosRegister(hosRegisterId);
        if (i == 1) {
            return new ResultUtil<>();
        }
        return new ResultUtil<>(500, "退号失败！");
    }

    /**
     * 通过id回显信息
     *
     * @param hosRegisterId
     * @return
     */
    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    public ResultUtil<Hosregister> findByHosRegisterId(@PathVariable("id") Integer hosRegisterId) {
        Hosregister hosregister = hosregisterService.queryById(hosRegisterId);
        if (hosregister != null) {
            return new ResultUtil<Hosregister>(hosregister);
        }
        return new ResultUtil<>(500, "信息不存在！");
    }

    /**
     * 更新挂号信息
     * @param hosregister
     * @param hosRegisterId
     * @return
     */
    @RequestMapping(value = "{id}", method = RequestMethod.PUT)
    public ResultUtil<Hosregister> updateHosRegister( Hosregister hosregister,@PathVariable("id") Integer hosRegisterId) {
        hosregister.setHosrId(hosRegisterId);
        System.out.println(hosregister);
        int i = hosregisterService.updateHosRegister(hosregister);
        if (i == 1) {
            return new ResultUtil<>();
        }
        return new ResultUtil<>(500, "更新失败");
    }
    /**
     * 查询所有科室信息
     * @return
     */
    @RequestMapping(value = "/keshi",method = RequestMethod.GET)
    public ResultUtil<Doctor> findKeshi(){
        List<Doctor> keshi = hosregisterService.findKeshi();
        if (keshi != null){
            return new ResultUtil(keshi);
        }
        return new ResultUtil(500,"信息不存在");
    }
    @RequestMapping(value = "/doctorName/{keshi}",method = RequestMethod.GET)
    public ResultUtil<Doctor> findDoctor(@PathVariable("keshi") String keshi){
        System.out.println(keshi);
        List<Doctor> doctorByKeshi = hosregisterService.findDoctorByKeshi(keshi);
        if (doctorByKeshi != null){
            return new ResultUtil(doctorByKeshi);
        }
        return new ResultUtil(500,"信息不存在");
    }
}
